﻿using System;
using System.Collections.Generic;
using System.Configuration.Provider;

namespace Altairis.Sewen.PageStore {

    public abstract class PageStoreProvider : ProviderBase {

        /// <summary>
        /// Loads latest available version of the page.
        /// </summary>
        /// <param name="name">Page title or slug.</param>
        /// <returns>Returns instance of <c>SewenPage</c> class or <c>null</c> when such page is not found.</returns>
        public virtual SewenPage LoadPage(string name) {
            return this.LoadPage(name, DateTime.Now);
        }

        /// <summary>
        /// Loads the version of the page, which was the latest available in time specified by <paramref name="version" /> parameter.
        /// </summary>
        /// <param name="name">Page title or slug.</param>
        /// <param name="version">The time decisive for version.</param>
        /// <returns>
        /// Returns instance of <c>SewenPage</c> class or <c>null</c> when such page is not found.
        /// </returns>
        public abstract SewenPage LoadPage(string name, DateTime version);

        /// <summary>
        /// Deletes all versions of the page.
        /// </summary>
        /// <param name="name">Page title or slug.</param>
        /// <returns>Returns <c>true</c> when page was deleted, <c>false</c> otherwise.</returns>
        public abstract bool DeletePage(string name);

        /// <summary>
        /// Deletes all versions of the page.
        /// </summary>
        /// <param name="name">Page title or slug.</param>
        /// <param name="version">The version time. This must be the exact page version time.</param>
        /// <returns>Returns <c>true</c> when page was deleted, <c>false</c> otherwise.</returns>
        public abstract bool DeletePage(string name, DateTime version);

        /// <summary>
        /// Loads all existing page versions.
        /// </summary>
        /// <param name="name">Page title or slug.</param>
        /// <returns>Returns list of all available versions of page or empty <code>IEnumerable&lt;&gt;</code> when no such page exists.</returns>
        public abstract IEnumerable<SewenPage> LoadPageVersions(string name);

        /// <summary>
        /// Saves new version of the page or creates new page if no previous version is found.
        /// </summary>
        /// <param name="page">The page to be saved.</param>
        public abstract void SavePage(SewenPage page);

        /// <summary>
        /// Finds all pages whose title contains the specified string.
        /// </summary>
        /// <param name="searchString">The search string.</param>
        /// <returns>List of all pages whose titles contain the specified string, or empty <code>IEnumerable&lt;&gt;</code> when no such pages found.</returns>
        public virtual IEnumerable<SewenPage> FindPagesByTitle(string searchString) {
            return this.FindPagesByTitle(searchString, StringSearchMode.Contains);
        }

        /// <summary>
        /// Finds all pages whose title begins, ends with or contains the specified string.
        /// </summary>
        /// <param name="searchString">The search string.</param>
        /// <param name="mode">The search mode.</param>
        /// <returns>List of all pages whose titles contain the specified string, or empty <code>IEnumerable&lt;&gt;</code> when no such pages found.</returns>
        public abstract IEnumerable<SewenPage> FindPagesByTitle(string searchString, StringSearchMode mode);

    }

}
